<template>
  <div class="view-switcher-wrapper" v-if="currentDashboard">
    <!-- 主体内容 -->
    <div class="switch-content">
      <h3 class="title">
        <span class="icon">📊</span>
        数据视图中枢
      </h3>
    </div>

    <div class="switch-group">
      <label
        v-for="option in options"
        :key="option.value"
        class="switch-option"
        :class="{ active: typeValue === option.value }"
        @click="changeView(option.value)"
      >
        {{ option.label }}
      </label>
    </div>

    <!-- 右侧状态提示 -->
    <div class="badge-indicator">
      {{ badgeText }}
    </div>
  </div>
</template>

<script setup lang="ts">
import { computed, ref } from "vue";
import useUserStore from "../../../../store/modules/user";
import { useRoute } from "vue-router";

const userApp = useUserStore();
const typeValue = ref("personal");
const route = useRoute();

const options = [
  { label: "个人数据", value: "personal" },
  { label: "小组数据", value: "team" },
];

const badgeText = computed(() => {
  return typeValue.value === "personal"
    ? "当前视角：您自己"
    : "团队作战模式 · 6人";
});

//
const changeView = (value: any) => {
  typeValue.value = value;
};

// 现实条件 必须是仪表盘 必须是业务组长
const currentDashboard = computed(() => {
  const roles = userApp.roles || []; // 假设 store 里有 roles 数组
  if (roles.includes("saleManager") && route.path.includes("/index")) {
    return true;
  }
  return false;
});
</script>

<style scoped lang="scss">
.view-switcher-wrapper {
  position: relative;
  height: 80%;
  flex: 1;
  z-index: 10; // 确保在最上层
  background: #ffffff;
  border: 1px solid #e0e0e0;
  border-radius: 50px;
  color: #333;
  display: flex;
  padding: 0 16px;
  align-items: center;
  justify-content: space-between;
  font-family: "Segoe UI", -apple-system, sans-serif;
}

.switch-content {
  display: flex;
  align-items: center;
}

// 标题区
.title {
  font-size: 16px;
  font-weight: 600;
  color: #0055b8;
  display: flex;
  align-items: center;
  gap: 6px;
  margin-right: 16px;

  .icon {
    font-size: 18px;
  }
}

// 切换按钮组
.switch-group {
  box-sizing: border-box;
  display: flex;
  background: #f5f7fa;
  border-radius: 20px;
  padding: 4px;
  font-size: 14px;
  border: 1px solid #dde1e6;
  height: 90%;

  .switch-option {
    cursor: pointer;
    padding: 6px 14px;
    border-radius: 16px;
    transition: all 0.25s ease;
    user-select: none;
    color: #495057;
    font-weight: 500;
    display: flex;
    justify-content: center;
    align-items: center;

    &.active {
      background: #007bff;
      color: #fff;
      font-weight: 600;
      box-shadow: 0 2px 6px rgba(0, 123, 255, 0.2);
    }

    &:hover:not(.active) {
      color: #0056b3;
      background: #edf0f5;
    }
  }
}

// 右侧状态提示
.badge-indicator {
  font-size: 13px;
  color: #6c757d;
  min-width: 180px;
  padding-left: 16px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
}
</style>

<!-- 全局动画定义（放在全局样式或此处） -->
<style lang="scss">
@keyframes pulse-ring {
  0% {
    transform: scale(0.8);
    opacity: 0.4;
  }
  50% {
    transform: scale(1.4);
    opacity: 0.6;
  }
  100% {
    transform: scale(0.8);
    opacity: 0.4;
  }
}
</style>
